package com.ruoyi.userManage.mapper;

import com.ruoyi.common.vo.IndexUserData;
import com.ruoyi.userManage.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户信息Mapper接口
 *
 * @author ruoyi
 * @date 2025-08-12
 */
public interface UserMapper {
    /**
     * 查询用户信息
     *
     * @param id 用户信息主键
     * @return 用户信息
     */
    public User selectUserById(Long id);

    /**
     * 查询用户信息列表
     *
     * @param user 用户信息
     * @return 用户信息集合
     */
    public List<User> selectUserList(User user);

    /**
     * 新增用户信息
     *
     * @param user 用户信息
     * @return 结果
     */
    public int insertUser(User user);

    /**
     * 修改用户信息
     *
     * @param user 用户信息
     * @return 结果
     */
    public int updateUser(User user);

    /**
     * 删除用户信息
     *
     * @param id 用户信息主键
     * @return 结果
     */
    public int deleteUserById(Long id);

    /**
     * 批量删除用户信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteUserByIds(Long[] ids);

    @Select("select id from t_user where phone = #{phone}")
    Long selectIdByPhone(@Param("phone") String phone);

    @Select("select phone from t_user where id = #{id}")
    String selectPhoneById(@Param("id") Long id);

    @Select("SELECT name FROM t_goods_class WHERE id=#{id}")
    String selClassNameId(@Param("id") Long id);

    @Select("SELECT\n" +
            "\tIFNULL(COUNT( DISTINCT CASE WHEN DATE( create_time ) = CURDATE() THEN user_id END ),0) AS currentUserData,\n" +
            "\tIFNULL(COUNT( DISTINCT CASE WHEN DATE( create_time ) = DATE_SUB( CURDATE(), INTERVAL 1 DAY ) THEN user_id END ),0) AS beforeUserData \n" +
            "FROM\n" +
            "\tt_draw_record")
    IndexUserData selectIndexUserData();

    @Select("select id from t_user where user_id = #{sixUserId}")
    Long selectUserIdBySixUserId(@Param("sixUserId") Long sixUserId);

    @Delete("delete from t_room_record where user_id = #{userId}")
    int deleteRoomRecordByUserId(@Param("userId") Long userId);
}
